var app = new Vue({
    el: '#app',
    data: {
        type: 1,
        listPost: [],
        listCommpany: [],
        bannerList: [],
        noMore: true,
        postTime: 1,
        loading: false,
        totalCommpany: 0,
        pageIndexCommpany: 1,
        pageSizeCommpany: 5,
        totalPost: 0,
        pageIndexPost: 1,
        pageSizePost: 5,
        userId: 0,
        cityId: 0,
    },
    created: function() {
        var that = this;
        if ($.getPara("userId") != "") {
            var userId = $.getPara("userId");
            this.userId = userId;
            $.setStorage("userId", userId)
        } else {
            if ($.getStorage("userId") && $.getStorage("userId") != "") {
                var userId = parseInt($.getStorage("userId"));
                this.userId = userId
            }
        }
        that.getBannerList();
        that.getPostList()
    },
    methods: {
        // 广告图
        getBannerList() {
            var that = this;
            console.log("招聘列表")
            $.ajax({
                type: "get",
                url: "/api/employee/adv/list",
                dataType: 'json',
                data: {
                    cityId: that.cityId,
                },
                success: function(res) {
                    if (res.data != "") {
                        $.each(res.data, function(index, val) {
                            that.bannerList.push(val)
                        })
                    }
                },
            })
            // console.log(that.bannerList)
        },
        // 招聘列表
        getPostList(time) {
            var that = this;
            var time = that.postTime;
            var pageIndex = that.pageIndexPost;
            var pageSize = that.pageSizePost;
            var id = id;
            $.ajax({
                type: "get",
                url:"/api/employee/list",
                dataType: 'json',
                data: {
                    time: time,
                    type: 1,
                    pageIndex: pageIndex,
                    pageSize: pageSize
                },
                success: function(res) {
                    if (res.data.list != "") {
                        $.each(res.data.list, function(index, val) {
                            that.listPost.push(val)
                        });
                        if (that.pageIndexPost == 1 && res.total <= that.pageSizePost) {
                            that.listPostNoMore = false
                        }
                        that.totalPost = res.data.total;
                        that.loading = false;
                        that.noMore = true
                    } else {
                        that.noMore = false
                    }
                },
            })
        },
        getCommentList(time) {
            var that = this;
            var time = that.postTime;
            var id = id;
            var pageIndex = that.pageIndexCommpany;
            var pageSize = that.pageSizeCommpany;
            $.ajax({
                type: "get",
                url:"/api/employee/list",
                dataType: 'json',
                data: {
                    time: time,
                    type: 2,
                    pageIndex: pageIndex,
                    pageSize: pageSize
                },
                success: function(res) {
                    if (res.data.list != "") {
                        $.each(res.data.list, function(index, val) {
                            that.listCommpany.push(val)
                        });
                        if (that.pageIndexCommpany == 1 && res.total <= that.pageSizeCommpany) {
                            that.listCommpanyNoMore = false
                        }
                        that.totalCommpany = res.data.total;
                        that.loading = false;
                        that.noMore = true
                    } else {
                        that.noMore = false
                    }
                },
            })
        },
        tabClick(type) {
            var that = this;
            if (type == 1 && that.type != 1) {
                that.pageIndexPost = 1;
                that.postTime = 1;
                that.listPost = [];
                that.type = 1;
                that.getPostList(that.postTime)
            } else if (type == 2 && that.type != 2) {
                that.postTime = 1;
                that.pageIndexCommpany = 1;
                that.listCommpany = [];
                that.type = 2;
                that.getCommentList(that.postTime)
            }
        },
        timeChoose(time) {
            var that = this;
            var time = time;
            var type = that.type;
            that.postTime = time;
            if (type == 1) {
                that.pageIndexPost = 1;
                that.listPost = [];
                that.getPostList(time)
            } else if (type == 2) {
                that.pageIndexCommpany = 1;
                that.listCommpany = [];
                that.getCommentList(time)
            }
        },
        moreList() {
            var that = this;
            var type = that.type;
            if (type == 1) {
                var total = that.totalPost;
                var index = that.pageIndexPost;
                var size = that.pageSizePost;
                var pagenum = Math.ceil(total / size);
                if (index < pagenum) {
                    that.pageIndexPost += index;
                    that.loading = false;
                    that.getPostList(that.postTime)
                } else if (index == pagenum || index > pagenum) {
                    that.noMore = false
                }
            }
            if (type == 2) {
                var total = that.totalCommpany;
                var index = that.pageIndexCommpany;
                var size = that.pageSizeCommpany;
                var pagenum = Math.ceil(total / size);
                if (index < pagenum) {
                    that.pageIndexCommpany += index;
                    that.loading = false;
                    that.getCommentList(that.postTime)
                } else if (index == pagenum || index > pagenum) {
                    that.noMore = false
                }
            }
        },
        toPostDetails(id) {
            var para = {};
            para.title = "职位详情";
            para.type = "equEvaluating";
            para.url = '/template/recruitDetails.html?id=' + id;
            if (this.userId > 0) {
                para.url = '/template/recruitDetails.html?id=' + id + "&userId=" + this.userId
            }
            if (/(Android)/i.test(navigator.userAgent)) {
                jsAndroid.appPush(JSON.stringify(para))
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                window.webkit.messageHandlers.appPush.postMessage(para)
            } else {
                window.location.href = para.url;
                alert("请使用移动设备！")
            }
        },
        toCommonDetails(id) {
            var para = {};
            para.title = "企业详情";
            para.type = "equEvaluating";
            para.url = '/template/recruitNextDetails.html?id=' + id;
            if (this.userId > 0) {
                para.url = '/template/recruitNextDetails.html?id=' + id + "&userId=" + this.userId
            }
            if (/(Android)/i.test(navigator.userAgent)) {
                jsAndroid.appPush(JSON.stringify(para))
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                window.webkit.messageHandlers.appPush.postMessage(para)
            } else {
                window.location.href = para.url;
                alert("请使用移动设备！")
            }
        },
    }
})
